package GUI;

import Communications.Search;
import Listeners.BookInfoFrameListener;
import Listeners.SearchActionListener;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.

 */
public class SearchPane extends JPanel{

    private static String[] values = {"Author","Title","ISBN","Category","Year","Price"};

    private static JComboBox list = new JComboBox(values);
    private JPanel all = new JPanel(new GridLayout(0,6));
    private static JTextField value = new JTextField(10);
    private JLabel lList = new JLabel("Criteria:    ");
    private JLabel lValue = new JLabel("Value:    ");
    private JButton search = new JButton("Search");
    private JButton view = new JButton("View Book");
    private static String selection;

    public SearchPane(){
           setup();
    }
    private void setup(){

        search.addActionListener(new SearchActionListener());

        lList.setHorizontalAlignment(SwingConstants.RIGHT);
        lValue.setHorizontalAlignment(SwingConstants.RIGHT);

        view.addActionListener(new BookInfoFrameListener());

        all.add(lList);
        all.add(list);
        all.add(lValue);
        all.add(value);
        all.add(search);
        all.add(view);

        this.add(all);

    }
    public static void search() throws IOException {

        if(value.getText().equals("")){
           JOptionPane.showMessageDialog(null,"Please Enter Search Value");
        }
        else{

            selection = (String) list.getSelectedItem();

            MainFrame.communicate.sendData(selection.charAt(0),value.getText());
            System.gc();

        }

    }

}
